#include <atomic>
#include <iostream>
#include <thread>

/**
 * @brief 标准实现普遍退化为 acquire，这里使用 acquire 代替 consume。
 */
int main() {
  std::atomic<bool> ready{false};
  int payload = 0;

  std::thread producer([&]() {
    payload = 7;
    ready.store(true, std::memory_order_release);  ///< 发布数据。
  });

  std::thread consumer([&]() {
    while (!ready.load(std::memory_order_acquire)) {  ///< 等价于 consume 的常见替代。
      std::this_thread::yield();
    }
    std::cout << "consume (as acquire) payload: " << payload << '\n';
  });

  producer.join();
  consumer.join();
  return 0;
}